<?php
/**
 * OS CRM SYSTEM - An open source application development framework for PHP 4.3.2 or newer
 *
 * CLASS - DONLOADS
 * 
 * @name      downloads
 * @package		OS CRM
 * @category  Class
 * @author		CRM SYSTEM Dev Team
 * @copyright	Copyright (c) 2010 - 2012, CRM SYSTEM
 * @since     Version 1.0
 * @filesource
 * @access    public 
 */

// ------------------------------------------------------------------------

class downloads extends Controller {
  
  /*common class varibale*/
  var $c 	= 'downloads';//current controler
	var $p_c = '';//parent controller
  
  //set db - listing data
	var $e_list_limit 	= '50';
	var $e_list_offset 	= '0';
	var $e_list_order   = 'asc';
	var $e_list_order_by= ''; 
  
  /*message strings*/
  var $valid_success 	= '';
  var $valid_errors 	= '';
  var $valid_notice 	= '';
  
  /**
   * downloads  - constructor of the class
   * 
   * @access public
   * @param  NA
   * @return void
   */
	function downloads()
	{
		parent::Controller();	
    
    if(!__is_loggedin()){
      redirect('login');
    }
    
    $this->lang->load('common', ADMIN_LANGUAGE);
	}
	
  /** 
	 * Index
	 *
	 * @desc NA
	 * @access public/private
	 * @param  NA	 
	 * @return void/mixed
	 */
	function index()
	{
		
	}
  
  /** 
	 * Journals
	 *
	 * @descp this will download a journal
	 * @access public
	 * @param  NA	 
	 * @return void
	 */
	function journals()
	{    
    output_file($file, $name, $mime_type);
  }
 
  
  /** 
	 * Articles
	 *
	 * @descp this will download an article
	 * @access public
	 * @param  NA	 
	 * @return void
	 */
	function articles()
	{    
    $os_articles_pdf = $this->input->post('hd_file');
    $os_articles_id = $this->input->post('hd_info');
    $art_info = _articles_file($os_articles_pdf, $os_articles_id);
    if(__is_loggedin()){
      
      if(!__chk_mem_dwl()){
        redirect('journals/maxdownloads');exit;
      }
      
      if(!empty($art_info['path'])){     
        
        $usr_info = __get_fuser();
        $data_i = array();
        $data_i['os_mem_id'] = $usr_info['usr_id'];
        $data_i['os_articles_id'] = $os_articles_id;
        $data_i['os_mem_dwl_dt'] = date(DB_DATE_FORMAT);
        $this->db->insert(TBL_MEM_DWL, $data_i); 
        
        $mime_type = 'application/pdf';
        $name = time() .'_'. $os_articles_pdf;
        $file = $art_info['path'];
        output_file($file, $name, $mime_type);      
      }    
    }else{
      $mime_type = 'application/pdf';
      $name = time() .'_'. $os_articles_pdf;
      $file = ROOTBASEPATH . 'images/media/nopdf.pdf';
      output_file($file, $name, $mime_type);      
    }
  }  

}

/* End of file login.php */
/* Location: ./system/application/modules/login/controllers/login.php */